/*
 * anima/firmware.hh - Generic firmware interface.
 * Copyright (C) 2007  Mikhail Vorozhtsov
 * See the LICENSE section of the README file for details.
 */

/* $Id$ */

#ifndef HEADER_ANIMA_FIRMWARE_HH
#define HEADER_ANIMA_FIRMWARE_HH

#include ANIMA_ARCH_HEADER (firmware.hh)
#include ANIMA_PLATFORM_HEADER (firmware.hh)
#include HEADER (elbp,elbp.hh)

START_NAMESPACE (anima)

class pdb;
class mm;

class firmware : public ANIMA_ARCH::firmware, public ANIMA_PLATFORM::firmware
{
  friend class pdb;
  friend class mm;

public:
  struct region_t : ANIMA_PLATFORM::firmware::region_t
  {
  public:
    u64_t addr;
    u64_t size;
    type_t type;

  public:
    static const char *type_string (type_t type);

  public:
    static bool find (u64_t addr, region_t &region);
    static const void *next (const void *prev, region_t &region);

  public:
    INLINE
    region_t ()
    {
      addr = 0;
      size = 0;
    }

    INLINE
    region_t (u64_t addr, u64_t size, type_t type)
    {
      this->addr = addr;
      this->size = size;
      this->type = type;
    }

  public:
    bool available_p () const;
    bool io_p () const;
  };

public:
  static bool init (const elbp::info_t *info);

private:
  static bool page_used_p (u64_t addr);
  static bool remap ();
};

END_NAMESPACE

#endif /* HEADER_ANIMA_FIRMWARE_HH */

